#ifndef _FRAME_H
#define _FRAME_H

#define FRAME_TYPE_AUTH 0x1
#define FRAME_TYPE_CONTROL 0x2
#define FRAME_TYPE_COMMAND 0x3
#define FRAME_TYPE_MESSAGE 0x4

#define FRAME_AUTH_TYPE_HELLO 0x1
#define FRAME_AUTH_TYPE_TOKEN 0x2
#define FRAME_AUTH_TYPE_FRAME 0x3
#define FRAME_AUTH_TYPE_ACCEPT 0x4
#define FRAME_AUTH_TYPE_DENY 0x5

#define FRAME_CTRL_TYPE_IDLE 0x0
#define FRAME_CTRL_TYPE_ACK 0x1
#define FRAME_CTRL_TYPE_NACK 0x2

#define FRAME_CMD_TYPE_NONE 0x0
#define FRAME_CMD_TYPE_LIST 0x1
#define FRAME_CMD_TYPE_GET 0x2
#define FRAME_CMD_TYPE_SEND 0x3
#define FRAME_CMD_TYPE_MARK 0x4
#define FRAME_CMD_TYPE_WHO 0x5

/* for network purpose */
struct frame_hdr_t {
	unsigned short type;
	unsigned short size;
	unsigned long seq;
	unsigned long ack;
} __attribute__((__packed__));;

typedef struct frame_hdr_t Frame_hdr_t;

/* for manipulation purpose */
typedef struct frame_t {
	unsigned short type;
	unsigned short size;
	unsigned long seq;
	unsigned long ack;
	char * content;
	struct frame_t * next;
} Frame_t;

struct _Frame_auth_hdr_t {
	unsigned short type;
	unsigned short size;
} __attribute__((__packed__));;

typedef struct _Frame_auth_hdr_t Frame_auth_hdr_t;

typedef struct _Frame_auth_t {
	Frame_auth_hdr_t * header;
	char * content;
} Frame_Auth_t;


/* frame.c */
char * frame_type_str( unsigned short type );
char * frame_auth_type_str( unsigned short type );
Frame_t *frame_create( void );
int frame_recv( Frame_t *, int sockfd );
int frame_send( Frame_t *, int sockfd );
void frame_destroy( Frame_t *frame );
void frame_display( Frame_t * frame );

#endif

